import os
import shutil
from gravityassist.musiclib import get_music_dir, refresh_music_list
from gravityassist.tools.download_video import download_video

def favorite_music(path: str):
    if not os.path.exists(path):
        if path.startswith('BV') or path.startswith('https://'):
            result = download_video(path)
            if not result.get('success') or path not in result:
                return {'success': False, 'message': 'For online music videos, use download_video tool to download first. Then use favorite_music again with the path returned by download_video.'}
            path = result['path']
        return {'success': False, 'message': 'File does not exist.'}
    favorite_folder = get_music_dir()
    shutil.copy(path, favorite_folder)
    refresh_music_list()
    return {'success': True, 'message': 'Music video added to the music library.'}
